package cn.javasm.web;

import cn.javasm.common.http.AxiosResult;
import cn.javasm.entity.Brand;
import cn.javasm.service.BrandService;
import cn.javasm.web.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version: 0.1
 */
@RestController
@RequestMapping("brand")
public class BrandController extends BaseController {

    @Autowired
    private BrandService brandService;

    @GetMapping
    public AxiosResult<List<Brand>> list(){
        return AxiosResult.success(brandService.list());
    }

    /**
     * 根据id查询一条数据
     */
    @GetMapping("{id}")
    public AxiosResult<Brand> findById(@PathVariable Long id){
        return AxiosResult.success(brandService.findById(id));
    }

    /**
     * 添加品牌数据
     */
    @PostMapping
    public AxiosResult<Void> add(@RequestBody Brand brand){
        return toAxios(brandService.add(brand));
    }

    /**
     * 更新品牌数据
     */
    @PutMapping
    public AxiosResult<Void> update(@RequestBody Brand brand){
        return toAxios(brandService.update(brand));
    }

    /**
     * 删除一条数据品
     */
    @DeleteMapping("{id}")
    public AxiosResult<Void> deleteById(@PathVariable Long id){
        return toAxios(brandService.deleteById(id));
    }

    /**
     * 删除多条数据
     */
    @DeleteMapping("batch/{ids}")
    public AxiosResult batchDeleteByIds(@PathVariable List<Long> ids){
        return toAxios(brandService.batchDeleteByIds(ids));
    }

}
